package com.android.sharedata;

import java.util.ArrayList;

import com.android.sharedata.provider.ShareDataContract;
import com.android.sharedata.provider.ShareDataContract.Received;
import com.android.sharedata.provider.ShareDataContract.Sent;

import android.os.Bundle;
import android.app.Activity;
import android.database.Cursor;
import android.util.Log;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ListReceivedActivity extends Activity {

	private Cursor mCursor;
	private ListView list;
	ArrayAdapter<String> adapter;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_received);
        
        //definition du curseur pour afficher tout les partage recu
        String columns[] = new String[] {Received.TITLE};
        mCursor = getContentResolver().query(ShareDataContract.Received.CONTENT_URI, columns, null, null, null);
        final ArrayList<String> allReceived = new ArrayList<String>();

        if(mCursor!=null){
        	if (mCursor.moveToFirst()) {
    			String title = null;
    			do {
    				title = mCursor.getString(mCursor.getColumnIndex(ShareDataContract.Received.TITLE));
    				allReceived.add(title);
    			} while (mCursor.moveToNext());
    		}
        }
        mCursor.close();
        
        adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,allReceived);
        list = (ListView) findViewById(R.id.listviewReceivedShare);
        list.setAdapter(adapter);
 
    }
}
